/**
 * 
 */
package nl.samenloop.bigscreen.component;

import java.awt.AlphaComposite;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JPanel;

import nl.samenloop.bigscreen.Constants;
import nl.samenloop.bigscreen.fx.Transparency;

/**
 * @author Bram Wiekens
 *
 */
@SuppressWarnings("serial")
public class TransparentPanel extends JPanel implements Transparency {
	
	private float opacity = 0.0f;
	
	public TransparentPanel(){
		super(true);
	}
	
	@Override
	public float getOpacity() {
		return opacity;
	}

	@Override
	public void setOpacity(float opacity) {
		this.opacity = opacity;
	}
	
	public void paint(Graphics g) {
		if (g != null) {
			Graphics2D g2 = (Graphics2D) g.create();
			
			g2.setBackground(Constants.PURPLE);
			g2.clearRect(0, 0, getWidth(), getHeight());

			g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));

			super.paint(g2);

			g2.dispose();
		}

	}

}
